package com.googlecode.controlecheque.database.helper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.googlecode.controlecheque.database.Banco;
import com.googlecode.controlecheque.database.Cheque;

public class DatabaseHelper extends SQLiteOpenHelper {

	private static final String DATABASE_NAME = "controle_cheque.db";
	private static final int DATABASE_VERSION = 1;

	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE " + Cheque.TABLE_NAME + " ("
                + Cheque._ID + " INTEGER PRIMARY KEY,"
                + Cheque.BANCO + " INTEGER,"
                + Cheque.AGENCIA + " INTEGER,"
                + Cheque.CONTA + " TEXT,"
                + Cheque.NUMERO_CHEQUE + " INTEGER,"
                + Cheque.VALOR + " NUMERIC,"
                + Cheque.DATA_EMISSAO + " INTEGER,"
                + Cheque.DATA_VENCIMENTO + " INTEGER,"
                + Cheque.CORRENTISTA + " TEXT,"
                + Cheque.CLIENTE + " INTEGER,"
                + Cheque.SITUACAO + " INTEGER"
                + ");");
        
        db.execSQL("CREATE TABLE " + Banco.TABLE_NAME + " ("
                + Banco._ID + " INTEGER PRIMARY KEY,"
                + Banco.CD_BANCO + " INTEGER,"
                + Banco.NM_BANCO + " TEXT"
                + ");");
    }

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + Cheque.TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + Banco.TABLE_NAME);
		onCreate(db);
	}

}
